package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.entity.EmployeeOutpass;
import com.amsp.oa.oademo.service.EmployeeOutpassService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Api(tags = "员工外出放行单管理")
@RestController
@RequestMapping("/api/employee-outpass")
public class EmployeeOutpassController {

    @Autowired
    private EmployeeOutpassService employeeOutpassService;

    @ApiOperation("分页查询")
    @GetMapping("/page")
    public IPage<EmployeeOutpass> getPage(
            @ApiParam("页码") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam("每页数量") @RequestParam(defaultValue = "10") Integer pageSize,
            @ApiParam("持单人姓名") @RequestParam(required = false) String holderName,
            @ApiParam("工号") @RequestParam(required = false) String employeeNumber) {
        return employeeOutpassService.getPage(pageNum, pageSize, holderName, employeeNumber);
    }

    @ApiOperation("根据ID查询")
    @GetMapping("/{id}")
    public EmployeeOutpass getById(@ApiParam("ID") @PathVariable Long id) {
        return employeeOutpassService.getById(id);
    }

    @ApiOperation("保存或更新")
    @PostMapping("/save")
    public boolean save(@ApiParam("员工外出放行单列表") @RequestBody List<EmployeeOutpass> outpassList) {
        return employeeOutpassService.saveBatchTransactional(outpassList);
    }

    @ApiOperation("删除")
    @DeleteMapping("/delete")
    public boolean delete(@ApiParam("ID列表") @RequestBody List<Long> ids) {
        return employeeOutpassService.deleteByIdsTransactional(ids);
    }
}